package first.niuke.simple;

import java.util.ArrayList;

/**
 * @ClassName NC70
 * @description:
 * @author: 荣燊
 * @create: 2021-06-11 10:52
 **/
public class NC70 {

    // 链表排序，将链表中最大值放到链表的尾部

    public ListNode sortInList (ListNode head) {
        // write code here
        ArrayList<Integer> list = new ArrayList<>();
        if (head == null || head.next == null) {
            return head;
        }
        ListNode tmp = head;
        while (tmp != null) {
            list.add(tmp.val);
            tmp = tmp.next;
        }
        list.sort((a,b)->{return a-b;});
        tmp = head;
        int i = 0;
        while (tmp != null) {
            tmp.val = list.get(i++);
            tmp = tmp.next;
        }
        return head;
    }

    public class ListNode {
        int val;
        ListNode next = null;
    }
}
